<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>分销设置</title>
    {template 'stourtravel/public/public_js'}
    {php echo Common::getCss('style.css,base.css,product.css,base_new.css'); }
    {php echo Common::getScript('config.js');}
    {php echo Common::getScript("uploadify/jquery.uploadify.min.js,jquery.validate.js"); }
    {php echo Common::getCss('uploadify.css','js/uploadify/'); }
    
</head>
<body>
	<table class="content-tab">
    <tr>
    <td width="119px" class="content-lt-td"  valign="top">
     {template 'stourtravel/public/leftnav'}
    <!--右侧内容区-->
    </td>
     <td valign="top" class="content-rt-td">
        <!--面包屑-->

      <div>
        <form id="frm">
         <div class="w-set-con">
         	<div class="cfg-header-bar">
         		<div class="cfg-header-tab">
         			{loop $productlist $product}
	                   <span class="menu-item item" id="menu_type_{$product['id']}" data-id="{$product['id']}">{$product['modulename']}</span>
	                {/loop}
         		</div>
         		<a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
         	</div>
          <div class="w-set-nr">

              {loop $productlist $product}
              <div class="picture ml-10 ratio-content" id="product_{$product['id']}" style="display: none;">
              	<ul class="info-item-block">
                    <li>
                        <span class="item-hd">排序：</span>
                        <div class="item-bd">
                           <input type="text" name="cfg_fenxiao_product_displayorder_{$product['id']}" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_product_displayorder_'.$product['id']]}">

                            <span class="item-text c-999">分销商中心推广商品类型显示顺序</span>
                        </div>
                    </li>
              		<li>
              			<span class="item-hd">反佣类型{Common::get_help_icon('fenxiao_commission_type')}：</span>
              			<div class="item-bd">
              				<label class="radio-label mr-20"><input type="radio" name="cfg_fenxiao_commission_type_{$product['id']}" class="fx_type" value="1" {if $info['cfg_fenxiao_commission_type_'.$product['id']]==1}checked="checked"{/if}>按订单金额百分比</label>
                            <label class="radio-label mr-20"><input type="radio" name="cfg_fenxiao_commission_type_{$product['id']}" class="fx_type" value="2" {if $info['cfg_fenxiao_commission_type_'.$product['id']]==2}checked="checked"{/if}>按平台收入百分比</label>
              				<label class="radio-label mr-20"><input type="radio" name="cfg_fenxiao_commission_type_{$product['id']}"   class="fx_type" value="0" {if $info['cfg_fenxiao_commission_type_'.$product['id']]==0}checked="checked"{/if}>现金</label>
              				<span class="item-text c-999">是按比例计算返佣金额还是直接返固定的金额</span>
              			</div>
              		</li>
              	</ul>
                <div class="typecon_1 typecon" style="{if $info['cfg_fenxiao_commission_type_'.$product['id']]!=1}display:none{/if}">
                  	<ul class="info-item-block">
                  		<li>
                  			<span class="item-hd">直属上级佣金比例：</span>
                  			<div class="item-bd">
                  				<input type="text" name="cfg_fenxiao_first_ratio_{$product['id']}" class="input-text w70" value="{php echo $info['cfg_fenxiao_first_ratio_'.$product['id']]}"/><span class="item-text c-999">%</span>
                  				<span class="item-text c-999 ml-10">分销商推荐买家购买后能拿到的佣金比例</span>
                  			</div>
                  		</li>
                  		<li>
                  			<span class="item-hd">二级上级佣金比例：</span>
                  			<div class="item-bd">
                  				<input type="text" name="cfg_fenxiao_second_ratio_{$product['id']}" class="input-text w70" value="{php echo $info['cfg_fenxiao_second_ratio_'.$product['id']]}"/><span class="item-text c-999">%</span>
                  				<span class="item-text c-999 ml-10">分销商推荐买家购买后，分销商的上级分销商能拿到的佣金比例</span>
                  			</div>
                  		</li>
                  		{if $level_num==3}
                  		<li>
                  			<span class="item-hd">三级上级佣金比例：</span>
                  			<div class="item-bd">
                  				<input type="text" name="cfg_fenxiao_third_ratio_{$product['id']}"  class="input-text w70" value="{php echo $info['cfg_fenxiao_third_ratio_'.$product['id']]}"/><span class="item-text c-999">%</span> 
                  				<span class="item-text c-999 ml-10">分销商推荐买家购买后，分销商上级的上级能拿到的佣金比例</span>
                  			</div>
                  		</li>
	                  	{/if}
	                  	<li>
	                  		<span class="item-hd">自购佣金比例：</span>
	                  		<div class="item-bd">
	                  			<input type="text" name="cfg_fenxiao_self_ratio_{$product['id']}"  class="input-text w70" value="{php echo $info['cfg_fenxiao_self_ratio_'.$product['id']]}"/><span class="item-text c-999">%</span> 
	                  			 <span class="item-text c-999 ml-10">分销商自已购买产品也可获得的佣金比例</span>
	                  		</div>
	                  	</li>
                  	</ul>
	               
                  </div>
                  <div class="typecon_2 typecon" style="{if $info['cfg_fenxiao_commission_type_'.$product['id']]!=2}display:none{/if}">
                      <ul class="info-item-block">
                          <li>
                              <span class="item-hd">直属上级佣金比例：</span>
                              <div class="item-bd">
                                  <input type="text" name="cfg_fenxiao_first_platform_ratio_{$product['id']}" class="input-text w70" value="{php echo $info['cfg_fenxiao_first_platform_ratio_'.$product['id']]}"/><span class="item-text c-999">%</span>
                                  <span class="item-text c-999 ml-10">分销商推荐买家购买后能拿到的佣金比例</span>
                              </div>
                          </li>
                          <li>
                              <span class="item-hd">二级上级佣金比例：</span>
                              <div class="item-bd">
                                  <input type="text" name="cfg_fenxiao_second_platform_ratio_{$product['id']}" class="input-text w70" value="{php echo $info['cfg_fenxiao_second_platform_ratio_'.$product['id']]}"/><span class="item-text c-999">%</span>
                                  <span class="item-text c-999 ml-10">分销商推荐买家购买后，分销商的上级分销商能拿到的佣金比例</span>
                              </div>
                          </li>
                          {if $level_num==3}
                          <li>
                              <span class="item-hd">三级上级佣金比例：</span>
                              <div class="item-bd">
                                  <input type="text" name="cfg_fenxiao_third_platform_ratio_{$product['id']}"  class="input-text w70" value="{php echo $info['cfg_fenxiao_third_platform_ratio_'.$product['id']]}"/><span class="item-text c-999">%</span>
                                  <span class="item-text c-999 ml-10">分销商推荐买家购买后，分销商上级的上级能拿到的佣金比例</span>
                              </div>
                          </li>
                          {/if}
                          <li>
                              <span class="item-hd">自购佣金比例：</span>
                              <div class="item-bd">
                                  <input type="text" name="cfg_fenxiao_self_platform_ratio_{$product['id']}"  class="input-text w70" value="{php echo $info['cfg_fenxiao_self_platform_ratio_'.$product['id']]}"/><span class="item-text c-999">%</span>
                                  <span class="item-text c-999 ml-10">分销商自已购买产品也可获得的佣金比例</span>
                              </div>
                          </li>
                      </ul>
                  </div>
                  <div class="typecon_0 typecon" style="{if $info['cfg_fenxiao_commission_type_'.$product['id']]!=0}display:none{/if}">
                  	<ul class="info-item-block">
                  		{if $product['id']!=1}
                  		<li>
                  			<span class="item-hd">直属上级佣金金额：</span>
                  			<div class="item-bd">
                  				<input type="text" name="cfg_fenxiao_first_cash_{$product['id']}"   class="input-text w70" value="{php echo $info['cfg_fenxiao_first_cash_'.$product['id']]}"/><span class="item-text c-999">元</span>  
                  				<span class="item-text c-999 ml-10">分销商推荐买家购买后能拿到的佣金金额</span>
                  			</div>
                  		</li>
                  		<li>
                  			<span class="item-hd">二级上级佣金金额：</span>
                  			<div class="item-bd">
                  				<input type="text" name="cfg_fenxiao_second_cash_{$product['id']}"  class="input-text w70" value="{php echo $info['cfg_fenxiao_second_cash_'.$product['id']]}"/><span class="item-text c-999">元</span>   
                  				<span class="item-text c-999 ml-10">分销商推荐买家购买后，分销商的上级分销商能拿到的佣金金额</span>
                  			</div>
                  		</li>
                  		{if $level_num==3}
                  		<li>
                  			<span class="item-hd">三级上级佣金金额：</span>
                  			<div class="item-bd">
                  				<input type="text" name="cfg_fenxiao_third_cash_{$product['id']}"  class="input-text w70" value="{php echo $info['cfg_fenxiao_third_cash_'.$product['id']]}"/><span class="item-text c-999">元</span>   
                  				<span class="item-text c-999 ml-10">分销商推荐买家购买后，分销商上级的上级能拿到的佣金金额</span>
                  			</div>
                  		</li>
                  		{/if}
                  		<li>
                  			<span class="item-hd">自购佣金金额：</span>
                  			<div class="item-bd">
                  				<input type="text" name="cfg_fenxiao_self_cash_{$product['id']}"  class="input-text w70" value="{php echo $info['cfg_fenxiao_self_cash_'.$product['id']]}"/><span class="item-text c-999">元</span>
                  				<span class="item-text c-999 ml-10">分销商自已购买产品也可获得的佣金金额</span>    
                  			</div>
                  		</li>
                  		{else}

                        {php  $people_group=Model_Sysconfig::get_people_group();}
                  		<li>
                  			<span class="item-hd">直属上级佣金金额：</span>
                  			<div class="item-bd">

                                {loop $people_group  $people}
                                {if $people['identifier']==2}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_first_cash_{$product['id']}" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_first_cash_'.$product['id']]}"/><span class="item-text">元</span>
                  				</div>
                                {elseif $people['identifier']==1}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_first_cash_{$product['id']}_child" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_first_cash_'.$product['id'].'_child']}"/><span class="item-text">元</span>
                  				</div>
                                {elseif $people['identifier']==3}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_first_cash_{$product['id']}_old" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_first_cash_'.$product['id'].'_old']}"/><span class="item-text">元</span>
                  				</div>
                                {/if}

                                {if $people['identifier']>3}
                                <div class="fl mr-20">
                                    <span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_first_cash_{$product['id']}_people{$people['identifier']}" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_first_cash_'.$product['id'].'_people'.$people['identifier']]}"/><span class="item-text">元</span>
                                </div>
                                {/if}
                                {/loop}
                  				<span class="item-text c-999">分销商推荐买家购买后能拿到的佣金金额</span>		
                  			</div>
                  		</li>
                  		<li>
                  			<span class="item-hd">二级上级佣金金额：</span>
                  			<div class="item-bd">
                                {loop $people_group  $people}
                                {if $people['identifier']==2}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_second_cash_{$product['id']}" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_second_cash_'.$product['id']]}"/><span class="item-text">元</span>
                  				</div>
                                {elseif $people['identifier']==1}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_second_cash_{$product['id']}_child" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_second_cash_'.$product['id'].'_child']}"/><span class="item-text">元</span>
                  				</div>
                                {elseif $people['identifier']==3}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_second_cash_{$product['id']}_old" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_second_cash_'.$product['id'].'_old']}"/><span class="item-text">元</span>
                  				</div>
                                {/if}

                                {if $people['identifier']>3}
                                <div class="fl mr-20">
                                    <span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_second_cash_{$product['id']}_people{$people['identifier']}" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_second_cash_'.$product['id'].'_people'.$people['identifier']]}"/><span class="item-text">元</span>
                                </div>
                                {/if}
                                {/loop}
                  				<span class="item-text c-999">分销商推荐买家购买后，分销商的上级分销商能拿到的佣金金额</span>		
                  			</div>
                  		</li>
                  		{if $level_num==3}
                  		<li>
                  			<span class="item-hd">三级上级佣金金额：</span>
                  			<div class="item-bd">

                                {loop $people_group  $people}
                                {if $people['identifier']==2}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_third_cash_{$product['id']}" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_third_cash_'.$product['id']]}"/><span class="item-text">元</span>
                  				</div>
                                {elseif $people['identifier']==1}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_third_cash_{$product['id']}_child" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_third_cash_'.$product['id'].'_child']}"/> <span class="item-text">元</span>
                  				</div>
                                {elseif $people['identifier']==3}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_third_cash_{$product['id']}_old" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_third_cash_'.$product['id'].'_old']}"/> <span class="item-text">元</span>
                  				</div>
                                {/if}


                                {if $people['identifier']>3}
                                <div class="fl mr-20">
                                    <span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_third_cash_{$product['id']}_people{$people['identifier']}" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_third_cash_'.$product['id'].'_people'.$people['identifier']]}"/><span class="item-text">元</span>
                                </div>
                                {/if}
                                {/loop}
                  				<span class="item-text c-999">分销商推荐买家购买后，分销商上级的上级能拿到的佣金金额</span>		
                  			</div>
                  		</li>
                  		{/if}
                  		<li>
                  			<span class="item-hd">自购佣金金额：</span>
                  			<div class="item-bd">
                                {loop $people_group  $people}

                                {if $people['identifier']==2}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_self_cash_{$product['id']}" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_self_cash_'.$product['id']]}"/> <span class="item-text">元</span>
                  				</div>
                                {elseif $people['identifier']==1}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_self_cash_{$product['id']}_child" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_self_cash_'.$product['id'].'_child']}"/> <span class="item-text">元</span>
                  				</div>
                                {elseif $people['identifier']==3}
                  				<div class="fl mr-20">
                  					<span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_self_cash_{$product['id']}_old" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_self_cash_'.$product['id'].'_old']}"/> <span class="item-text">元</span>
                  				</div>
                                {/if}

                                {if $people['identifier']>3}
                                <div class="fl mr-20">
                                    <span class="item-text">{$people['name']}</span><input type="text" name="cfg_fenxiao_self_cash_{$product['id']}_people{$people['identifier']}" class="input-text w70 mr-5 ml-5" value="{php echo $info['cfg_fenxiao_self_cash_'.$product['id'].'_people'.$people['identifier']]}"/><span class="item-text">元</span>
                                </div>
                                {/if}
                                {/loop}

                  				<span class="item-text c-999">分销商自已购买产品也可获得的佣金金额</span>		
                  			</div>
                  		</li>
                  		{/if}
                  	</ul>	
                  </div>
                  <div class="lh-30 ml-10">
                  	<a href="javascript:;" class="btn-link set_product" typeid="{$product['id']}" typename="{$product['modulename']}">设置具体产品反佣</a>
                  	<span class="c-999">如果某一产品的对应的反佣比例未设置或为0，那么系统将使用当前页设置的全局反佣比例或现金</span>
                  </div>
                  
              </div>
              {/loop}
            <div class="clear clearfix pt-20 pb-20">
            	<a class="btn btn-primary radius size-L ml-115" id="btn_save" href="javascript:;">保存</a>
            </div>
            
          </div>
        </div>
            <input type="hidden" name="groupid" id="groupid" value="{$groupid}"/>
        </form>
      </div>
  </td>
  </tr>
  </table>

  
  
	<script>

	$(document).ready(function(){
        var group_name = "{$group_name}";


        //信息验证
        $("#frm").validate({
            focusInvalid:false,
            rules: {
               {loop $productlist $key $product}
                 cfg_fenxiao_product_displayorder_{$product['id']}:
                 {
                     digits:true,
                     min:1,
                     max:99
                 }
                {if $key<count($productlist)-1}
                  ,
                 {/if}
               {/loop}
            },
            messages: {
                  {loop $productlist $key $product}
                        cfg_fenxiao_product_displayorder_{$product['id']}:
                        {
                            digits:"只能输入整数",
                            min:"最小为1",
                            max:"最大为99"
                        }
                    {if $key<count($productlist)-1}
                     ,
                    {/if}
                  {/loop}
            },
            ignore:[],
            errUserFunc:function(element){
                  var id=$(element).parents('.picture:first').attr('id');
                   id= id.replace('product_','');
                   $("#menu_type_"+id).trigger('click');
            },
            submitHandler:function(form){
                Ext.Ajax.request({
                    url   :  SITEURL+"fenxiao/admin/product/ajax_reward_save",
                    method  :  "POST",
                    isUpload :  true,
                    form  : "frm",
                    success  :  function(response, opts)
                    {
                        var data = $.parseJSON(response.responseText);
                        if(data.status)
                        {
                            ST.Util.showMsg('保存成功!','4',2000);
                        }
                    }
                });
                return false;//阻止常规提交
            }
        });















        //配置信息保存
        $("#btn_save").click(function(){

            $("#frm").submit();

        })

        //设置具体产品返佣
        $(".set_product").click(function(){
            var typeid=$(this).attr('typeid');
            var typename=$(this).attr('typename');
            var groupid = $("#groupid").val();
            var url = SITEURL+'fenxiao/admin/product/list/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}typeid/'+typeid+'/groupid/'+groupid;
            parent.window.addTab('设置'+typename+'产品佣金：'+group_name,url,1);
        });


        //切换
        $(".fx_type").click(function(){
                var typeVal=$(this).val();
              $(this).parents('.ratio-content:first').find(".typecon").hide();
              $(this).parents('.ratio-content:first').find(".typecon_"+typeVal).show();
        });

        $(".menu-item").click(function(){
              $(this).addClass('on');
              $(this).siblings().removeClass('on');
              var id=$(this).attr("data-id");
              $(".ratio-content").hide();
              $("#product_"+id).show();
        });
        $(".menu-item:first").trigger('click');
     });
    </script>

</body>
</html>
